$(function () {
	//游戏名称
	window.gameName = 'answer-question';
	//当前题序号
	var curIdx = 0;
	//当前正确答案
	var rightIdx = '';
	//总得分
	var totalScore = 0;

	//判断用户是否有抽奖(游戏)资格
	api.eligibleToPlay(uid, act_id, vote_token);
	//获取活动参数
	api.getGameConfig(act_id, gameName);

	//模拟数据
	var fetchData = [
		{
			question: '你姐姐的老公你应该叫什么？',
			answer: ['姐姐','哥哥','亲爱的','姐夫'],
			right: 3
		},
		{
			question: '你妈妈的爸爸你应该叫什么？',
			answer: ['爷爷','奶奶','老头','外公'],
			right: 3
		},
		{
			question: '球王梅西的宠物狗叫什么？',
			answer: ['C罗','马地奥','浩克','托尼'],
			right: 2
		},
		{
			question: '你妹妹的妈妈你应该叫什么？',
			answer: ['妈妈','阿姨','姑姑','奶奶'],
			right: 0
		}
	];

	//装载题目
	function preloadData(index) {
		var data = fetchData[index];
		$('#questionBox').html('Q'+(index+1)+':'+data.question+' (10分)');
		var html = '';
		data.answer.map(function (ele, i) {
			html += '<li class="answer-item">'+ele+'</li>';
		});
		$('#answer-box').html(html);
		rightIdx = data.right;
	}
	preloadData(curIdx);

	//点击下一题
	$('#next-btn').on('click', function () {
		//当前选择答案
		var userIdx = $('#answer-box .active').index();
		if (userIdx<0) {
			Toast('请先选择答案');
			return;
		} else if (userIdx == rightIdx) {
			totalScore += 10;
		}

		var len = fetchData.length;
		if (curIdx == len-1) {
			$('.total-score span').text(totalScore);
			if (totalScore>10) { //成功
				$('#sucessPage').show();
			} else { //失败
				$('#failPage').show();
			}
		} else {
			curIdx++;
			preloadData(curIdx);
		}
	})

	//点击[开始答题]按钮
	$('#startBtn').on('click',function () {
		$('#startPage').hide();
		$('#gamePage').show();
		gameBegin();
	});

	//回答问题
	$('#answer-box').on('click','.answer-item',function () {
		if ($(this).hasClass('active')) return;
		$('#answer-box .active').removeClass('active');
		$(this).addClass('active');
	})

	//游戏开始
	window.gameBegin = function () {
		//次数减少一次
		limitNum--;
		
	};

	
});


